/**
 *查询水量年报表与搜索框的模糊查询，有模糊查询，传日期名称字段
 */

var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
        {
            title: '序号', dataIndex: 'flowDailyReportId',width:'6%', renderer: function (value, obj, index) {
                return index + 1;
            }
        },
        {title: '设备名称', dataIndex: 'deviceName',width:'16%'},
        {
            title: '一月', dataIndex: 'januaryWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '二月', dataIndex: 'februaryWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '三月', dataIndex: 'marchWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '四月', dataIndex: 'aprilWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '五月', dataIndex: 'mayWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '六月', dataIndex: 'juneWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '七月', dataIndex: 'julyWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '八月', dataIndex: 'augustWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '九月', dataIndex: 'septemberWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {title: '十月', dataIndex: 'octoberWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {
            title: '十一月', dataIndex: 'novemberWaterAmount',width:'6%', renderer: function (value) {
                return value == null || value == "" ? 0 : value;
            }
        },
        {title: '十二月', dataIndex: 'decemberWaterAmount',width:'6%', renderer: function (value) {
                return value==null||value==""?0:value;
            }
        },
        {
            title: '合计', dataIndex: '',width:'6%', renderer: function (value,obj) {
                var sum=obj.januaryWaterAmount+obj.februaryWaterAmount+obj.marchWaterAmount+obj.aprilWaterAmount+obj.mayWaterAmount+obj.juneWaterAmount+obj.augustWaterAmount+obj.septemberWaterAmount+obj.octoberWaterAmount+obj.novemberWaterAmount+obj.decemberWaterAmount;
                return sum;
            }
        }
    ];
//分页查询
var store = new Store({
        url: '/rest/web/flowDailyReport/selectFlowYearReportPage',
        autoLoad: true, //自动加载数据
        params: { //配置初始请求的参数
            length: '10',
            start: '0',
            createTime: new Date(new Date()).Format("yyyy")
        },
        pageSize: 10,	// 配置分页数目
        root: 'data.list',
        totalProperty: 'data.totalCount'
    }),
    grid = new Grid.Grid({
        render: '#grid',
        columns: columns,
        loadMask: true, //加载数据时显示屏蔽层
        store: store,
        plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
        // 底部工具栏
        bbar: {
            pagingBar: true
        }
    });

grid.render();

/**模糊搜索**/
var form = new BUI.Form.HForm({
    srcNode: '#searchForm'
}).render();

form.on('beforesubmit', function (ev) {
    //序列化成对象
    var obj = form.serializeToObject();
    obj.start = 0; //返回第一页
    store.load(obj);
    return false;
});
//点击查询
var createTime="";
$("#queryBtn").click(function(){
    $("#getDate").val($("input[name='createTime']").val());
    createTime= $("#getDate").val();
});
//点击导出按钮，导出数据
function exportData(){
    if($("#getDate").val()==""){
        window.location.href = "/rest/web/flowDailyReport/excelYearWaterAmountDownload?createTime="+new Date(new Date()).Format("yyyy");
    }else{
        window.location.href = "/rest/web/flowDailyReport/excelYearWaterAmountDownload?createTime="+createTime;
    }
}
